package com.grz.day50.controller;

import com.grz.day50.entity.MailProperties;
import com.grz.day50.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MailController {

    @Autowired
    private JavaMailSender mailSender;

    @Autowired
    private MailProperties mailProperties;

    @Value("${spring.mail.username}")
    private String from;


    @Autowired
    private Student student;

    @PostMapping("/sendMail")
    public String send(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);
        return "success";
    }

    @GetMapping("/info")
    public String getInfo() {
        System.out.println(mailProperties.getHost());
        return "success";
    }


    @GetMapping("/student")
    public String getStudent() {
        System.out.println(student.toString());
        return "success";
    }
}